
if (typeof jQuery === 'undefined') {

    throw new Error('CommonUtils.js must need Jquery plugin!!');

}

!(function () {

    var obj = {

        /**
         * 刷新标签页
         * @param tabElement                @需要刷新的Tab的Dom元素
         * @param tabUrl                    @Tab的Url
         */
        refreshTab: function(tabElement, tabUrl) {

            if($(tabElement).length != 0) {

                var currentTab = $(tabElement).tabs('getSelected');

            } else {

                var currentTab = parent.$(tabElement).tabs('getSelected');

            }

            var currentTabIframe = currentTab.find('iframe');

            if(currentTabIframe.length > 0) {

                currentTabIframe.attr("src", currentTabIframe.attr("src"));

            } else {

                currentTab.panel("refresh", tabUrl);

            }

        },

        /**
         * 创建新的标签页
         * @param tabElement                @Tab的Dom元素
         * @param tabName                   @Tab标题名
         * @param tabHref                   @Tab的Url
         * @param isIframe                  @是否需要为iframe的Tab标签页
         * @param isNeedFindExistTabs       @是否需要找存在的标签页
         */
        openTab: function(tabElement, tabName, tabHref, isIframe, isNeedFindExistTabs) {

            var _self = this;

            var options = {

                title: tabName,

                closable: true,

                fit: true,

                border: false,

                tools: [{

                    iconCls: 'icon-mini-refresh',

                    handler: function () {

                        _self.refreshTab(tabElement, tabHref);

                    }

                }]

            }

            if(isNeedFindExistTabs) {

                var isExistTab = $(tabElement).tabs('exists', tabName);

                if(isExistTab) {

                    $(tabElement).tabs('select', tabName);

                    return false;

                }

            }

            if(isIframe) {

                options.content = "<iframe src='" + tabHref + "' width='100%' height='95%' frameborder='0'></iframe>";

            } else {

                options.href = tabHref;

            }

            if($(tabElement).length == 0) {

                parent.$(tabElement).tabs('add', options);

            } else {

                $(tabElement).tabs('add', options);

            }



        }

    };

    window.TabsUtils = obj;

})(jQuery);


